<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <meta HTTP-EQUIV="expires" CONTENT="0">
    <title>律师管理管理</title>
    <link rel="stylesheet" href="../../css/element.css">
    <link rel="stylesheet" href="../../css/base.css">
</head>
<body>
<div id="wrapper" v-cloak>
    <div style="padding-bottom: 10px">
            <el-breadcrumb separator-class="el-icon-arrow-right">
                <el-breadcrumb-item @click.native="parent.changeIndex('index')">首页</el-breadcrumb-item>
                <el-breadcrumb-item>律师管理管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>

        <div style="height: 1px; margin: 10px 0; background-color: white"></div>
    <el-input size='small' v-model="search" style="width: 20%;" suffix-icon="el-icon-search" placeholder="请输入律师名称按回车搜索"
              @keyup.enter.native="loadTable"></el-input>
    <el-button size='small' @click="add" type="primary"  style="margin: 10px 0">新增</el-button>
<!--    <el-upload action="/files/upload" :on-success="successUpload" :show-file-list="false" style="display: inline-block">-->
<!--        <el-button size='small' type="primary">导入</el-button>-->
<!--    </el-upload>-->
<!--    <el-button size='small' @click="exp" type="primary"  style="margin: 10px 0">导出</el-button>-->
    <el-table :data="tableData" border stripe style="width: 100%">
        <el-table-column prop="id" label="ID" width="100"> </el-table-column>
        <el-table-column prop="name" label="律师姓名"></el-table-column>
        <el-table-column prop="gender" label="性别"></el-table-column>
        <el-table-column prop="birth" label="出生日期"></el-table-column>
        <el-table-column prop="contactNumber" label="电话号码"></el-table-column>
        <el-table-column prop="email" label="邮箱"></el-table-column>
        <el-table-column prop="address" label="地址"></el-table-column>
        <el-table-column prop="expertise" label="专长领域"></el-table-column>
        <el-table-column prop="licenseNumber" label="执业资格证书编号"></el-table-column>
        <el-table-column prop="licenseIssuingAuthority" label="执业资格证书颁发机构"></el-table-column>
        <el-table-column prop="licenseIssueDate" label="执业资格证书颁发日期"></el-table-column>
        <el-table-column prop="isApproved" label="是否审核通过"></el-table-column>
<!--        <el-table-column prop="createTime" label="创建日期"></el-table-column>-->
<!--        <el-table-column prop="updateTime" label="更新时间"></el-table-column>-->

        <el-table-column
          fixed="right"
          label="操作"
          width="200">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" circle size='small' @click="edit(scope.row)"></el-button>
          <el-popconfirm
              @onConfirm="del(scope.row.id)"
              title="确定删除？"
          >
            <el-button size='small' type="danger" icon="el-icon-delete" circle slot="reference" style="margin-left: 10px"></el-button>
          </el-popconfirm>
        </template>
        </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div style="background-color: white">
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageNum"
                :page-sizes="[5, 10, 20, 40]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </div>

    <el-dialog title="律师管理信息" :visible.sync="dialogFormVisible" width="40%"
               :close-on-click-modal="false">
        <el-form :model="entity">
            <el-form-item label="律师姓名" label-width="120px">
                <el-input v-model="entity.name" autocomplete="off" style="width: 80%"></el-input>
            </el-form-item>
            <!--头像-->
            <el-form-item label="头像" label-width="120px">
                <div style="padding: 5px 0; text-align: center">
                    <el-upload
                            class="avatar-uploader"
                            action="/files/upload"
                            :show-file-list="false"
                            :on-success="handleAvatarSuccess">
                        <img v-if="entity.avatar" :src="['/files/' + entity.avatar]"
                             style="height: 100px;width: 100px;display: block" class="avatar">
                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                    </el-upload>
                </div>
            </el-form-item>
            <el-form-item label="性别" label-width="120px">
                <el-select v-model="entity.gender" placeholder="请选择性别" style="width: 80%">
                    <el-option label="男" value="男"></el-option>
                    <el-option label="女" value="女"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="出生日期" label-width="120px">
                <el-date-picker style="width: 80%" v-model="entity.birth" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
            </el-form-item>
            <el-form-item label="电话号码" label-width="120px">
                <el-input v-model="entity.contactNumber" autocomplete="off" style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="邮箱" label-width="120px">
                <el-input v-model="entity.email" autocomplete="off" style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="地址" label-width="120px">
                <el-input v-model="entity.address" autocomplete="off" style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="专长领域" label-width="120px">
                <el-input v-model="entity.expertise" autocomplete="off" style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="执业资格证书编号" label-width="120px">
                <el-input v-model="entity.licenseNumber" autocomplete="off" style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="执业资格证书颁发机构" label-width="120px">
                <el-input v-model="entity.licenseIssuingAuthority" autocomplete="off" style="width: 80%"></el-input>
            </el-form-item>
            <el-form-item label="执业资格证书颁发日期" label-width="120px">
                <el-date-picker style="width: 80%" v-model="entity.licenseIssueDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
            </el-form-item>
            <el-form-item label="是否审核通过" label-width="120px">
                <el-select v-model="entity.isApproved" placeholder="请选择状态" style="width: 80%">
                    <el-option label="审核通过" value="审核通过"></el-option>
                    <el-option label="未通过" value="未通过"></el-option>
                    <el-option label="待审核" value="待审核"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="save">确 定</el-button>
        </div>
    </el-dialog>
</div>

<script src="../../js/jquery.min.js"></script>
<script src="../../js/vue.min.js"></script>
<script src="../../js/element.js"></script>
<script src="../../js/tinymce/tinymce.min.js"></script>


<script>

    let urlBase = "/api/lawyer/";
    new Vue({
        el: "#wrapper",
        data: {
            options: [],
            fileList: [],
            user: {},
            tableData: [],
            pageNum: 1,
            pageSize: 10,
            total: 0,
            dialogFormVisible: false,
            entity: {},
            isCollapse: false,
            search: '',
        },
        created() {
            this.user = sessionStorage.getItem("user") ? JSON.parse(sessionStorage.getItem("user")) : {};
            this.loadTable();
        },
        methods: {
            handleAvatarSuccess(res) {
                this.entity = JSON.parse(JSON.stringify(this.entity))
                this.entity.avatar = res.data
                this.save()
            },
            fileSuccessUpload(res) {
                this.entity.file = "http://localhost:9999/files/" + res.data;
                this.entity.img = "http://localhost:9999/files/" + res.data;
                console.log(res)
            },
            successUpload(value) {
                $.get("/api/lawyer/upload/" + value.data).then(res => {
                    if (res.code === '0') {
                        this.$message({
                            message: "导入成功",
                            type: "success"
                        });
                        this.loadTable()
                    }
                })
            },
            changeState(obj, state) {  // 审核
                this.entity = JSON.parse(JSON.stringify(obj));
                this.entity.state = state;
                this.save();
            },
            handleCollapse() {
                this.isCollapse = !this.isCollapse;
            },
            logout() {
                $.get("/api/user/logout");
                sessionStorage.removeItem("user");
                location.href = "/page/end/login.html";
            },
            loadTable() {
                $.get(urlBase + "/page?pageNum=" + this.pageNum + "&pageSize=" + this.pageSize + "&name=" + this.search).then(res => {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                })

                 // $.get("/api/").then(res => {
                    // this.options = res.data;
                 // })
            },
            exp() {   // excel 导出
                window.open(urlBase + "/export");
            },
            handleSizeChange(pageSize) {
                this.pageSize = pageSize;
                this.loadTable();
            },
            handleCurrentChange(pageNum) {
                this.pageNum = pageNum;
                this.loadTable();
            },
            add() {
                this.entity = {};
                this.fileList = [];
                this.dialogFormVisible = true;
            },
            save() {
                let type = this.entity.id ? "PUT" : "POST";
                $.ajax({
                    url: urlBase,
                    type: type,
                    contentType: "application/json",
                    data: JSON.stringify(this.entity)
                }).then(res => {
                    if (res.code === '0') {
                        this.$message({
                            message: "保存成功",
                            type: "success"
                        });
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        })
                    }
                    this.loadTable();
                    this.dialogFormVisible = false;
                })
            },
            edit(obj) {
                this.entity = JSON.parse(JSON.stringify(obj));
                this.fileList = [];
                this.dialogFormVisible = true;
            },
            del(id) {
                $.ajax({
                    url: urlBase + id,
                    type: "delete"
                }).then(res => {
                    if (res.code === '0') {
                        this.$message({
                            message: "删除成功",
                            type: "success"
                        })
                        this.loadTable();
                    } else {
                        this.$message({
                            message: res.msg,
                            type: "error"
                        })
                    }
                })
            }
        }
    })
</script>
</body>
</html>
